package Jets.ui
{
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import Jets.display.JContainer;
	
	public class JRichImage extends JContainer
	{
		private var _tf:TextField;
		private var cframe:int = 0;
		private var faceSign:Array;
		
		function JRichImage(parent:DisplayObjectContainer=null, cx:Number=0, cy:Number=0) 
		{
			this.faceSign = [];
			super(parent,cx,cy);
		}
		
		override public function set width(value:Number) : void 
		{
			if(_width != value)
			{
				_width = value;
				this._tf.width = value;
				this.checkFaces(this.data as String);
			}
		}
		
		override protected function addChildren() : void 
		{
			this._tf = new TextField();
			this._tf.type = TextFieldType.DYNAMIC;
			this._tf.selectable = false;
			this._tf.width = width;
			this._tf.multiline = true;
			this._tf.wordWrap = true;
			this._tf.textColor = 0x0c212b;
			this._tf.autoSize = TextFieldAutoSize.LEFT;
			this.addChild(this._tf);
		}
		
		private function onlink(event:Event) : void 
		{
			this.dispatchEvent(event);
		}
		
		override public function get height() : Number 
		{
			return this._tf.textHeight + 2;
		}
		override public function get width():Number
		{
			return this._tf.width;
		}
		public function get textWidth():Number
		{
			return this._tf.textWidth;
		}
		
		public function destroy() : void 
		{
		}
		
		override public function set data(value:Object) : void 
		{
			if(value != data)
			{
				super.data = value;
				this.checkFaces(data as String);
			}
		}
		
		public function checkFaces(value:String) : void 
		{
			if(value == null)
			{
				return;
			}
			var tx:TextField = this._tf;
			this.faceSign = [];
			var rg:RegExp = new RegExp("#[0-9]{2}","g");
			this.faceSign = value.match(rg);
			if(this.faceSign.length == 0)
			{
				tx.htmlText = value;
				return;
			}
			tx.htmlText = value.replace(rg,"<space>　</space>");
			this.cframe = 0;
		}
		
	}
}